From cf1792902ff879b2cbafe54f160c5d4c5f70b4d4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 13 Jan 2015 20:04:43 -0800 Subject: [PATCH] Add a short section about path dependencies Closes #640 --- src/bin/build.rs | 4 ++-- src/doc/guide.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/bin/build.rs b/src/bin/build.rs index ec1c02e85..c6d35849b 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -43,8 +43,8 @@ current package is built. For more information on SPEC and its format, see the `cargo help pkgid` command. Compilation can be configured via the use of profiles which are configured in -the manifest. The default profile for this command is `dev`, but passing the ---release flag will use the `release` profile instead. +the manifest. The default profile for this command is `dev`, but passing +the --release flag will use the `release` profile instead. "; pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult> { diff --git a/src/doc/guide.md b/src/doc/guide.md index 027b41c51..f44c83684 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -392,6 +392,34 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured Of course, if your project has tests, you'll see more output, with the correct number of tests. +# Path Dependencies + +Over time our `hello_world` project has grown significantly in size! It's gotten +to the point that we probably want to split out a separate crate for others to +use. To do this Cargo supports **path dependencies** which are typically +sub-crates that live within one repository. Let's start off by making a new +crate inside of our `hello_world` project: + +```shell +# inside of hello_world/ +$ cargo new hello_utils +``` + +This will create a new folder `hello_utils` inside of which a `Cargo.toml` and +`src` folder are ready to be configured. In order to tell Cargo about this, open +up `hello_world/Cargo.toml` and add these lines: + +```toml +[dependencies.hello_utils] +path = "hello_utils" +``` + +This tells Cargo that we depend on a crate called `hello_utils` which is found +in the `hello_utils` folder (relative to the `Cargo.toml` it's written in). + +And that's it! The next `cargo build` will automatically build `hello_utils` and +all of its own dependencies, and others can also start using the crate as well. + ## Travis-CI To test your project on Travis-CI, here is a sample `.travis.yml` file: -- 2.30.2